'''
数据库配置
'''
from mongoengine import connect
from mongoengine.connection import get_connection
from config.settings import get_settings
from logger.logger import logger

settings = get_settings()
try :
    connect(
           settings.MONGODB_DATABASE,
           alias=settings.MONGODB_DATABASE,
           host=settings.MONGODB_HOST,
           port=settings.MONGODB_PORT
       )
    conn = get_connection(settings.MONGODB_DATABASE)
    conn.server_info()  # 触发实际连接并获取服务器信息
    logger.info("MongoDB连接成功")
except Exception as e:
    logger.error(f"MongoDB连接失败: {e}")